import requests
import execjs

cookies = {
    'btoken': 'K900S8M6QIMELAKQ8B1ONJ48AO4V1894',
    'Hm_lvt_42317524c1662a500d12d3784dbea0f8': '1698125522',
    'hy_data_2020_id': '18b602b268194b-0f94d620a8f445-26031151-2073600-18b602b2682fc3',
    'hy_data_2020_js_sdk': '%7B%22distinct_id%22%3A%2218b602b268194b-0f94d620a8f445-26031151-2073600-18b602b2682fc3%22%2C%22site_id%22%3A211%2C%22user_company%22%3A105%2C%22props%22%3A%7B%7D%2C%22device_id%22%3A%2218b602b268194b-0f94d620a8f445-26031151-2073600-18b602b2682fc3%22%7D',
    'Hm_lpvt_42317524c1662a500d12d3784dbea0f8': '1698219893',
}

headers = {
    'authority': 'www.xiniudata.com',
    'accept': 'application/json',
    'accept-language': 'zh-CN,zh;q=0.9',
    'content-type': 'application/json',
    # 'cookie': 'btoken=K900S8M6QIMELAKQ8B1ONJ48AO4V1894; Hm_lvt_42317524c1662a500d12d3784dbea0f8=1698125522; hy_data_2020_id=18b602b268194b-0f94d620a8f445-26031151-2073600-18b602b2682fc3; hy_data_2020_js_sdk=%7B%22distinct_id%22%3A%2218b602b268194b-0f94d620a8f445-26031151-2073600-18b602b2682fc3%22%2C%22site_id%22%3A211%2C%22user_company%22%3A105%2C%22props%22%3A%7B%7D%2C%22device_id%22%3A%2218b602b268194b-0f94d620a8f445-26031151-2073600-18b602b2682fc3%22%7D; Hm_lpvt_42317524c1662a500d12d3784dbea0f8=1698219893',
    'origin': 'https://www.xiniudata.com',
    'referer': 'https://www.xiniudata.com/industry/newest?from=data',
    'sec-ch-ua': '"Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36',
}

js_file = open("解析烯牛JS.js", "r", encoding="utf-8").read()

r = {
    "payload": {
        "sort": 2,
        "start": 19,
        "limit": 20
    }
}
js_response_data = execjs.compile(js_file).call("parseEncrypt",r)

json_data = {
    'payload': js_response_data['payload'],
    'sig': js_response_data['sig'],
    'v': 1,
}

response = requests.post(
    'https://www.xiniudata.com/api2/service/x_service/person_industry_list/list_industries_by_sort',
    cookies=cookies,
    headers=headers,
    json=json_data,
)
encrypt_data = response.json()['d']

js_encrypt_data = execjs.compile(js_file).call("parseDecrypt",encrypt_data)
for item in js_encrypt_data['list']:
    print(item)
